const {
    Mysql
} = require('../tools/utils');
module.exports = async ctx => {
    let {
        coverImg,
        isNew,
        isVip,
        sort,
        title,
        isFree,
        price,
        type,
        videoUrl
    } = ctx.request.body;
    if (isFree != 'undefined' && price != 'undefined' && isFree != 0) {
        let sql = `INSERT INTO video(coverImg,isNew,isVip,sort,title,type,videoUrl,isFree,price) VALUES('${coverImg}',${isNew},${isVip},'${sort}','${title}',${type},'${videoUrl}',${isFree},${price})`;
        try {
            await Mysql(sql);
            ctx.state.data = {
                msg: 'ok'
            }
        } catch (error) {
            ctx.state.data = {
                msg: 'fail'
            }
        }
    } else {
        let sql = `INSERT INTO video(coverImg,isNew,isVip,sort,title,type,videoUrl) VALUES('${coverImg}',${isNew},${isVip},'${sort}','${title}',${type},'${videoUrl}')`;
        try {
            await Mysql(sql);
            ctx.state.data = {
                msg: 'ok'
            }
        } catch (error) {
            ctx.state.data = {
                msg: 'fail'
            }
        }
    }

};